{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Parameter Histogram\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import py_eddy_tracker_sample\nfrom matplotlib import pyplot as plt\nfrom numpy import arange\n\nfrom py_eddy_tracker.observations.tracking import TrackEddiesObservations"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Load an experimental med atlas over a period of 26 years (1993-2019)\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "a = TrackEddiesObservations.load_file(\n    py_eddy_tracker_sample.get_demo_path(\n        \"eddies_med_adt_allsat_dt2018/Anticyclonic.zarr\"\n    )\n)\nc = TrackEddiesObservations.load_file(\n    py_eddy_tracker_sample.get_demo_path(\"eddies_med_adt_allsat_dt2018/Cyclonic.zarr\")\n)\nkwargs_a = dict(label=\"Anticyclonic\", color=\"r\", histtype=\"step\", density=True)\nkwargs_c = dict(label=\"Cyclonic\", color=\"b\", histtype=\"step\", density=True)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure(figsize=(12, 7))\n\nfor x0, name, title, xmax, factor, bins in zip(\n    (0.4, 0.72, 0.08),\n    (\"speed_radius\", \"speed_average\", \"amplitude\"),\n    (\"Speed radius (km)\", \"Speed average (cm/s)\", \"Amplitude (cm)\"),\n    (100, 50, 20),\n    (0.001, 100, 100),\n    (arange(0, 2000, 1), arange(0, 1000, 0.5), arange(0.0005, 1000, 0.2)),\n):\n    ax_hist = fig.add_axes((x0, 0.24, 0.27, 0.35))\n    nb_a, _, _ = ax_hist.hist(a[name] * factor, bins=bins, **kwargs_a)\n    nb_c, _, _ = ax_hist.hist(c[name] * factor, bins=bins, **kwargs_c)\n    ax_hist.set_xticklabels([])\n    ax_hist.set_xlim(0, xmax)\n    ax_hist.grid()\n\n    ax_cum = fig.add_axes((x0, 0.62, 0.27, 0.35))\n    ax_cum.hist(a[name] * factor, bins=bins, cumulative=-1, **kwargs_a)\n    ax_cum.hist(c[name] * factor, bins=bins, cumulative=-1, **kwargs_c)\n    ax_cum.set_xticklabels([])\n    ax_cum.set_title(title)\n    ax_cum.set_xlim(0, xmax)\n    ax_cum.set_ylim(0, 1)\n    ax_cum.grid()\n\n    ax_ratio = fig.add_axes((x0, 0.06, 0.27, 0.15))\n    ax_ratio.set_xlim(0, xmax)\n    ax_ratio.set_ylim(0, 2)\n    ax_ratio.plot((bins[1:] + bins[:-1]) / 2, nb_c / nb_a)\n    ax_ratio.axhline(1, color=\"k\")\n    ax_ratio.grid()\n    ax_ratio.set_xlabel(title)\n\nax_cum.set_ylabel(\"Cumulative\\npercent distribution\")\nax_hist.set_ylabel(\"Percent of observations\")\nax_ratio.set_ylabel(\"Ratio percent\\nCyc/Acyc\")\nax_cum.legend()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}